package hash;

import java.util.HashSet;
import java.util.Set;

/**
 * @author 十八岁讨厌编程
 * @date 2025/6/27 21:15
 * @PROJECT_NAME leetcode
 * @description
 */

public class Solution202 {


    public boolean isHappy(int n) {
        int sum = n;
        Set<Integer> record = new HashSet<>();
        while (sum != 1) {
            int num = sum;
            sum = 0;
            while (num >= 1) {
                int temp = num % 10;
                sum += temp * temp;
                num /= 10;
            }
            if (record.contains(sum)) return false;
            record.add(sum);
        }
        return true;
    }


}
